﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FileExplorerServiceHost
{
    using System.Reflection;

    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Closed += new EventHandler(MainWindow_Closed);
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            Properties.Settings.Default["CurrentDirectory"] = App.ViewModel.CurrentDownloadDirectory;
            Properties.Settings.Default.Save();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataContext = App.ViewModel;
            var downloadPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DowloadRoot");
            var uploadPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "UploadRoot");
            App.ViewModel.CurrentDownloadDirectory = string.IsNullOrEmpty(Properties.Settings.Default.DownloadDirectory) ? downloadPath : Properties.Settings.Default.DownloadDirectory;
            App.ViewModel.CurrentUploadDirectory = string.IsNullOrEmpty(Properties.Settings.Default.UploadDirectory) ? uploadPath : Properties.Settings.Default.UploadDirectory;
            
            App.ViewModel.Start();
        }
    }
}
